package com.paas.user.compoment.impl;

import com.paas.user.compoment.MailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

/**
 * @author pangjs
 * @version 0.1
 * @date 2021/6/19 2:14 下午
 * @description
 */

@Service
@Slf4j
public class MailServiceImpl implements MailService {

    // springboot 提供发送邮件的简单抽象 直接注入
    @Autowired
    private JavaMailSender mailSender;

    @Value("${spring.mail.from}")
    private String form;

    @Override
    public void sendMail(String to, String subject, String content) {

        //消息
        SimpleMailMessage message = new SimpleMailMessage();

        //配置邮箱发送人
        message.setFrom(form);

        //收件人
        message.setTo(to);
        //主题
        message.setSubject(subject);
        //内容
        message.setText(content);

        mailSender.send(message);

        log.info("邮件发送成功 {}" ,message);
    }
}
